
if Net_OUT==0
    load(['Var_Estimates_',num2str(sim_tol),'_OR.mat'])
else
    load(['Var_Estimates_',num2str(sim_tol),'_OUT.mat'])
end
    

    

%%% (1) Network Formation Parameters Estimates

SE_Net = sqrt(diag(VarEst.Var_BGD_hat));

Net_Estimates = zeros(32,4);
Net_Estimates(1,1) = VarEst.BGD_hat(1);
Net_Estimates(2,1) = sqrt(diag(VarEst.Var_BGD_hat(1,1)));
Net_Estimates(3,1) = VarEst.BGD_hat(15);
Net_Estimates(4,1) = sqrt(diag(VarEst.Var_BGD_hat(15,15)));
Net_Estimates(5,1) = VarEst.BGD_hat(55);
Net_Estimates(6,1) = sqrt(diag(VarEst.Var_BGD_hat(55,55)));

for i=1:4
    if i==1
        m=1;
    end
    if i==2
        m=15;
    end
    if i==3
        m=28;
    end
    if i==4
        m=41;
    end
    for j=1:13
        Net_Estimates(6+2*j-1,i) = VarEst.BGD_hat(m+j);
        Net_Estimates(6+2*j,i) = sqrt(diag(VarEst.Var_BGD_hat(m+j,m+j)));
    end
end

Net_Estimates
if Net_OUT==0
    matrix2latex(Net_Estimates,['Table6.tex'], 'format','%-9.3f')
end

%% (2) Peer Effects Estimates
% With no endogenous peer effect
PE_Estimates = zeros(30,4);
for i=1:9
    PE_Estimates(2*i-1,1) = VarEst.alpha_educ_m3(i);
    PE_Estimates(2*i,1) = sqrt(VarEst.Var_alpha_educ_m3(i,i)); 
    
    PE_Estimates(2*i-1,3) = VarEst.alpha_gender_m3(i);
    PE_Estimates(2*i,3) = sqrt(VarEst.Var_alpha_gender_m3(i,i));
end

for i=1:15
    PE_Estimates(2*i-1,2) = VarEst.alpha_educ_m4(i);
    PE_Estimates(2*i,2) = sqrt(VarEst.Var_alpha_educ_m4(i,i));

    PE_Estimates(2*i-1,4) = VarEst.alpha_gender_m4(i);
    PE_Estimates(2*i,4) = sqrt(VarEst.Var_alpha_gender_m4(i,i));
    
end

PE_Estimates
if Net_OUT==0
    matrix2latex(PE_Estimates,['Table7.tex'], 'format','%-9.3f')
else
    matrix2latex(PE_Estimates,['TableA15.tex'], 'format','%-9.3f')
end
    


%% (3) T1 Sims
    % Import Data
    load('Mats_T1');
    N_T1 = size(Cons_T1.X_raw,1);
    
    if Net_OUT==0
        load(['Sims_T1_',num2str(sim_tol),'_',num2str(Sim_reps),'_OR.mat']);
    else
        load(['Sims_T1_',num2str(sim_tol),'_',num2str(Sim_reps),'_OUT.mat']);
    end
        

    
    
    Cat_mat_educ = bsxfun(@times,(ones(N_T1,1)-MISS_T1.y1_educ_MISS),[ones(N_T1,1), Cons_T1.X_raw(:,1), ones(N_T1,1) - Cons_T1.X_raw(:,1), Cons_T1.X_raw(:,4:6), ones(N_T1,1) - Cons_T1.X_raw(:,4) - Cons_T1.X_raw(:,5) - Cons_T1.X_raw(:,6)]);
    Cat_mat_gender = bsxfun(@times,(ones(N_T1,1)-MISS_T1.y1_gender_MISS),[ones(N_T1,1), Cons_T1.X_raw(:,1), ones(N_T1,1) - Cons_T1.X_raw(:,1), Cons_T1.X_raw(:,4:6), ones(N_T1,1) - Cons_T1.X_raw(:,4) - Cons_T1.X_raw(:,5) - Cons_T1.X_raw(:,6)]);
   
    
    % Main tables (no endog PE)
    Table_Sims_T1_educ = zeros(8,7);
    for i=1:size(Cat_mat_educ,2)
        Table_Sims_T1_educ(1,i) = ( sum(NetOut_T1.y1_educ.*(ones(N_T1,1)-MISS_T1.y1_educ_MISS).*Cat_mat_educ(:,i)) )/sum((ones(N_T1,1)-MISS_T1.y1_educ_MISS).*Cat_mat_educ(:,i));
        Table_Sims_T1_educ(2,i) = 1/sqrt(sum((ones(N_T1,1)-MISS_T1.y1_educ_MISS).*Cat_mat_educ(:,i)))*( sum( (NetOut_T1.y1_educ.^2).*(ones(N_T1,1)-MISS_T1.y1_educ_MISS).*Cat_mat_educ(:,i)) )/sum((ones(N_T1,1)-MISS_T1.y1_educ_MISS).*Cat_mat_educ(:,i)); - Table_Sims_T1_educ(1,i)^2;
        Table_Sims_T1_educ(3,i) = sum((ones(N_T1,1)-MISS_T1.y1_educ_MISS).*Cat_mat_educ(:,i));
        
        Table_Sims_T1_educ(5,i) = sum(sum( bsxfun(@times,bsxfun(@times,Cat_mat_educ(:,i),(ones(N_T1,1)-MISS_T1.y1_educ_MISS)),Sims_Out.y1_educ_M1_m3)))/ (Sim_reps * sum((ones(N_T1,1)-MISS_T1.y1_educ_MISS).*Cat_mat_educ(:,i)) );
        Table_Sims_T1_educ(6,i) = sum(sum( bsxfun(@times,bsxfun(@times,Cat_mat_educ(:,i),(ones(N_T1,1)-MISS_T1.y1_educ_MISS)),Sims_Out.y1_educ_M2_m3)))/ (Sim_reps * sum((ones(N_T1,1)-MISS_T1.y1_educ_MISS).*Cat_mat_educ(:,i)) );
        Table_Sims_T1_educ(7,i) = sum(sum( bsxfun(@times,bsxfun(@times,Cat_mat_educ(:,i),(ones(N_T1,1)-MISS_T1.y1_educ_MISS)),Sims_Out.y1_educ_m3)))/ (Sim_reps * sum((ones(N_T1,1)-MISS_T1.y1_educ_MISS).*Cat_mat_educ(:,i)) );
        Table_Sims_T1_educ(8,i) = sum(sum( bsxfun(@times,bsxfun(@times,Cat_mat_educ(:,i),(ones(N_T1,1)-MISS_T1.y1_educ_MISS)),Sims_Out.y1_educ_m4)))/ (Sim_reps * sum((ones(N_T1,1)-MISS_T1.y1_educ_MISS).*Cat_mat_educ(:,i)) );
        
    end
    Table_Sims_T1_educ
    
    
    Table_Sims_T1_gender = zeros(8,7);
    for i=1:size(Cat_mat_gender,2)
        Table_Sims_T1_gender(1,i) = ( sum(NetOut_T1.y1_gender.*(ones(N_T1,1)-MISS_T1.y1_gender_MISS).*Cat_mat_gender(:,i)) )/sum((ones(N_T1,1)-MISS_T1.y1_gender_MISS).*Cat_mat_gender(:,i));
        Table_Sims_T1_gender(2,i) = 1/sqrt(sum((ones(N_T1,1)-MISS_T1.y1_gender_MISS).*Cat_mat_gender(:,i)))*( sum( (NetOut_T1.y1_gender.^2).*(ones(N_T1,1)-MISS_T1.y1_gender_MISS).*Cat_mat_gender(:,i)) )/sum((ones(N_T1,1)-MISS_T1.y1_gender_MISS).*Cat_mat_gender(:,i)); - Table_Sims_T1_gender(1,i)^2;
        Table_Sims_T1_gender(3,i) = sum((ones(N_T1,1)-MISS_T1.y1_gender_MISS).*Cat_mat_gender(:,i));
        
        Table_Sims_T1_gender(5,i) = sum(sum( bsxfun(@times,bsxfun(@times,Cat_mat_gender(:,i),(ones(N_T1,1)-MISS_T1.y1_gender_MISS)),Sims_Out.y1_gender_M1_m3)))/ (Sim_reps * sum((ones(N_T1,1)-MISS_T1.y1_gender_MISS).*Cat_mat_gender(:,i)) );
        Table_Sims_T1_gender(6,i) = sum(sum( bsxfun(@times,bsxfun(@times,Cat_mat_gender(:,i),(ones(N_T1,1)-MISS_T1.y1_gender_MISS)),Sims_Out.y1_gender_M2_m3)))/ (Sim_reps * sum((ones(N_T1,1)-MISS_T1.y1_gender_MISS).*Cat_mat_gender(:,i)) );
        Table_Sims_T1_gender(7,i) = sum(sum( bsxfun(@times,bsxfun(@times,Cat_mat_gender(:,i),(ones(N_T1,1)-MISS_T1.y1_gender_MISS)),Sims_Out.y1_gender_m3)))/ (Sim_reps * sum((ones(N_T1,1)-MISS_T1.y1_gender_MISS).*Cat_mat_gender(:,i)) );
        Table_Sims_T1_gender(8,i) = sum(sum( bsxfun(@times,bsxfun(@times,Cat_mat_gender(:,i),(ones(N_T1,1)-MISS_T1.y1_gender_MISS)),Sims_Out.y1_gender_m4)))/ (Sim_reps * sum((ones(N_T1,1)-MISS_T1.y1_gender_MISS).*Cat_mat_gender(:,i)) );
        
        
    end
    Table_Sims_T1_gender

    if Net_OUT==0
        matrix2latex([Table_Sims_T1_educ; Table_Sims_T1_gender],['TableA3.tex'], 'format','%-9.3f')
    else
        matrix2latex([Table_Sims_T1_educ; Table_Sims_T1_gender],['TableA17.tex'], 'format','%-9.3f')
    end

    
  
%% Pref Sims
    load('Mats_T2C');
    N_T2C = size(Cons_T2C.X_raw,1);
 
    % Educ
 
    Cat_mat_educ = [ones(N_T2C,1), Cons_T2C.L_educ, Cons_T2C.M_educ, Cons_T2C.H_educ];
    Mean_Outcome_educ_pref = zeros(4,7);  
    
    % All (no preference)
    if Net_OUT==0
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_OR.mat']);
    else
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_OUT.mat']);
    end
        
    Pct_LMH = [];
    for i=2:4
        Pct_LMH = [Pct_LMH, bsxfun(@rdivide,sum(bsxfun(@times,Cat_mat_educ(:,i),Sims_Out.P_sim),1),sum(bsxfun(@times,Cat_mat_educ(:,1),Sims_Out.P_sim),1))'];
    end    
    
    Means_educ = [];
    for i=1:size(Cat_mat_educ,2)
        Means_educ = [Means_educ, sum(bsxfun(@rdivide,bsxfun(@times,Cat_mat_educ(:,i),Sims_Out.y1_educ_m4),sum(Cat_mat_educ(:,i),1)))'];
    end
    
    for i=1:Sim_reps
        Mean_Outcome_educ_pref(1,1) = Mean_Outcome_educ_pref(1,1) + Means_educ(i,1)/Sim_reps;
        Mean_Outcome_educ_pref(1,2) = Mean_Outcome_educ_pref(1,2) + Means_educ(i,2)/Sim_reps;
        Mean_Outcome_educ_pref(1,3) = Mean_Outcome_educ_pref(1,3) + Means_educ(i,3)/Sim_reps;
        Mean_Outcome_educ_pref(1,4) = Mean_Outcome_educ_pref(1,4) + Means_educ(i,4)/Sim_reps;
        Mean_Outcome_educ_pref(1,5) = Mean_Outcome_educ_pref(1,5) + Pct_LMH(i,1)/Sim_reps;
        Mean_Outcome_educ_pref(1,6) = Mean_Outcome_educ_pref(1,6) + Pct_LMH(i,2)/Sim_reps;
        Mean_Outcome_educ_pref(1,7) = Mean_Outcome_educ_pref(1,7) + Pct_LMH(i,3)/Sim_reps;
    end
    
    
    
    % L_educ
    if Net_OUT==0
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_L_educ_pref_OR.mat']);
    else
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_L_educ_pref_OUT.mat']);
    end
        

    
    Pct_LMH = [];
    for i=2:4
        Pct_LMH = [Pct_LMH, bsxfun(@rdivide,sum(bsxfun(@times,Cat_mat_educ(:,i),Sims_Out.P_sim),1),sum(bsxfun(@times,Cat_mat_educ(:,1),Sims_Out.P_sim),1))'];
    end    
    
    Means_educ = [];
    for i=1:size(Cat_mat_educ,2)
        Means_educ = [Means_educ, sum(bsxfun(@rdivide,bsxfun(@times,Cat_mat_educ(:,i),Sims_Out.y1_educ_m4),sum(Cat_mat_educ(:,i),1)))'];
    end
    
    for i=1:Sim_reps
        Mean_Outcome_educ_pref(2,1) = Mean_Outcome_educ_pref(2,1) + Means_educ(i,1)/Sim_reps;
        Mean_Outcome_educ_pref(2,2) = Mean_Outcome_educ_pref(2,2) + Means_educ(i,2)/Sim_reps;
        Mean_Outcome_educ_pref(2,3) = Mean_Outcome_educ_pref(2,3) + Means_educ(i,3)/Sim_reps;
        Mean_Outcome_educ_pref(2,4) = Mean_Outcome_educ_pref(2,4) + Means_educ(i,4)/Sim_reps;
        Mean_Outcome_educ_pref(2,5) = Mean_Outcome_educ_pref(2,5) + Pct_LMH(i,1)/Sim_reps;
        Mean_Outcome_educ_pref(2,6) = Mean_Outcome_educ_pref(2,6) + Pct_LMH(i,2)/Sim_reps;
        Mean_Outcome_educ_pref(2,7) = Mean_Outcome_educ_pref(2,7) + Pct_LMH(i,3)/Sim_reps;
    end
    
 
    
    
    % M_educ
    if Net_OUT==0
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_M_educ_pref_OR.mat']);
    else
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_M_educ_pref_OUT.mat']);
    end
    
    Pct_LMH = [];
    for i=2:4
        Pct_LMH = [Pct_LMH, bsxfun(@rdivide,sum(bsxfun(@times,Cat_mat_educ(:,i),Sims_Out.P_sim),1),sum(bsxfun(@times,Cat_mat_educ(:,1),Sims_Out.P_sim),1))'];
    end    
    
    Means_educ = [];
    for i=1:size(Cat_mat_educ,2)
        Means_educ = [Means_educ, sum(bsxfun(@rdivide,bsxfun(@times,Cat_mat_educ(:,i),Sims_Out.y1_educ_m4),sum(Cat_mat_educ(:,i),1)))'];
    end
    
    for i=1:Sim_reps
        Mean_Outcome_educ_pref(3,1) = Mean_Outcome_educ_pref(3,1) + Means_educ(i,1)/Sim_reps;
        Mean_Outcome_educ_pref(3,2) = Mean_Outcome_educ_pref(3,2) + Means_educ(i,2)/Sim_reps;
        Mean_Outcome_educ_pref(3,3) = Mean_Outcome_educ_pref(3,3) + Means_educ(i,3)/Sim_reps;
        Mean_Outcome_educ_pref(3,4) = Mean_Outcome_educ_pref(3,4) + Means_educ(i,4)/Sim_reps;
        Mean_Outcome_educ_pref(3,5) = Mean_Outcome_educ_pref(3,5) + Pct_LMH(i,1)/Sim_reps;
        Mean_Outcome_educ_pref(3,6) = Mean_Outcome_educ_pref(3,6) + Pct_LMH(i,2)/Sim_reps;
        Mean_Outcome_educ_pref(3,7) = Mean_Outcome_educ_pref(3,7) + Pct_LMH(i,3)/Sim_reps;
    end

    
    % H_educ
    if Net_OUT==0
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_H_educ_pref_OR.mat']);
    else
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_H_educ_pref_OUT.mat']);
    end
    
    Pct_LMH = [];
    for i=2:4
        Pct_LMH = [Pct_LMH, bsxfun(@rdivide,sum(bsxfun(@times,Cat_mat_educ(:,i),Sims_Out.P_sim),1),sum(bsxfun(@times,Cat_mat_educ(:,1),Sims_Out.P_sim),1))'];
    end    
    
    Means_educ = [];
    for i=1:size(Cat_mat_educ,2)
        Means_educ = [Means_educ, sum(bsxfun(@rdivide,bsxfun(@times,Cat_mat_educ(:,i),Sims_Out.y1_educ_m4),sum(Cat_mat_educ(:,i),1)))'];
    end
    
    for i=1:Sim_reps
        Mean_Outcome_educ_pref(4,1) = Mean_Outcome_educ_pref(4,1) + Means_educ(i,1)/Sim_reps;
        Mean_Outcome_educ_pref(4,2) = Mean_Outcome_educ_pref(4,2) + Means_educ(i,2)/Sim_reps;
        Mean_Outcome_educ_pref(4,3) = Mean_Outcome_educ_pref(4,3) + Means_educ(i,3)/Sim_reps;
        Mean_Outcome_educ_pref(4,4) = Mean_Outcome_educ_pref(4,4) + Means_educ(i,4)/Sim_reps;
        Mean_Outcome_educ_pref(4,5) = Mean_Outcome_educ_pref(4,5) + Pct_LMH(i,1)/Sim_reps;
        Mean_Outcome_educ_pref(4,6) = Mean_Outcome_educ_pref(4,6) + Pct_LMH(i,2)/Sim_reps;
        Mean_Outcome_educ_pref(4,7) = Mean_Outcome_educ_pref(4,7) + Pct_LMH(i,3)/Sim_reps;
    end    
        

    
    Mean_Outcome_educ_pref
    

    
    % Gender
    Cat_mat_gender = [ones(N_T2C,1), Cons_T2C.L_gender, Cons_T2C.M_gender, Cons_T2C.H_gender];
    Mean_Outcome_gender_pref = zeros(4,7);
   
    
    % All (no preference)
    if Net_OUT==0
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_OR.mat']);
    else
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_OUT.mat']);
    end
        

    Pct_LMH = [];
    for i=2:4
        Pct_LMH = [Pct_LMH, bsxfun(@rdivide,sum(bsxfun(@times,Cat_mat_gender(:,i),Sims_Out.P_sim),1),sum(bsxfun(@times,Cat_mat_gender(:,1),Sims_Out.P_sim),1))'];
    end    
    
    Means_gender = [];
    for i=1:size(Cat_mat_gender,2)
        Means_gender = [Means_gender, sum(bsxfun(@rdivide,bsxfun(@times,Cat_mat_gender(:,i),Sims_Out.y1_gender_m4),sum(Cat_mat_gender(:,i),1)))'];
    end
    
    for i=1:Sim_reps
        Mean_Outcome_gender_pref(1,1) = Mean_Outcome_gender_pref(1,1) + Means_gender(i,1)/Sim_reps;
        Mean_Outcome_gender_pref(1,2) = Mean_Outcome_gender_pref(1,2) + Means_gender(i,2)/Sim_reps;
        Mean_Outcome_gender_pref(1,3) = Mean_Outcome_gender_pref(1,3) + Means_gender(i,3)/Sim_reps;
        Mean_Outcome_gender_pref(1,4) = Mean_Outcome_gender_pref(1,4) + Means_gender(i,4)/Sim_reps;
        Mean_Outcome_gender_pref(1,5) = Mean_Outcome_gender_pref(1,5) + Pct_LMH(i,1)/Sim_reps;
        Mean_Outcome_gender_pref(1,6) = Mean_Outcome_gender_pref(1,6) + Pct_LMH(i,2)/Sim_reps;
        Mean_Outcome_gender_pref(1,7) = Mean_Outcome_gender_pref(1,7) + Pct_LMH(i,3)/Sim_reps;
    end
    

    
    
    % L_gender
    if Net_OUT==0
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_L_gender_pref_OR.mat']);
    else
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_L_gender_pref_OUT.mat']);
    end
    
    Pct_LMH = [];
    for i=2:4
        Pct_LMH = [Pct_LMH, bsxfun(@rdivide,sum(bsxfun(@times,Cat_mat_gender(:,i),Sims_Out.P_sim),1),sum(bsxfun(@times,Cat_mat_gender(:,1),Sims_Out.P_sim),1))'];
    end    
    
    Means_gender = [];
    for i=1:size(Cat_mat_gender,2)
        Means_gender = [Means_gender, sum(bsxfun(@rdivide,bsxfun(@times,Cat_mat_gender(:,i),Sims_Out.y1_gender_m4),sum(Cat_mat_gender(:,i),1)))'];
    end
    
    for i=1:Sim_reps
        Mean_Outcome_gender_pref(2,1) = Mean_Outcome_gender_pref(2,1) + Means_gender(i,1)/Sim_reps;
        Mean_Outcome_gender_pref(2,2) = Mean_Outcome_gender_pref(2,2) + Means_gender(i,2)/Sim_reps;
        Mean_Outcome_gender_pref(2,3) = Mean_Outcome_gender_pref(2,3) + Means_gender(i,3)/Sim_reps;
        Mean_Outcome_gender_pref(2,4) = Mean_Outcome_gender_pref(2,4) + Means_gender(i,4)/Sim_reps;
        Mean_Outcome_gender_pref(2,5) = Mean_Outcome_gender_pref(2,5) + Pct_LMH(i,1)/Sim_reps;
        Mean_Outcome_gender_pref(2,6) = Mean_Outcome_gender_pref(2,6) + Pct_LMH(i,2)/Sim_reps;
        Mean_Outcome_gender_pref(2,7) = Mean_Outcome_gender_pref(2,7) + Pct_LMH(i,3)/Sim_reps;
    end
    
    
    
    
    % M_gender
    if Net_OUT==0
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_M_gender_pref_OR.mat']);
    else
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_M_gender_pref_OUT.mat']);
    end
    
    Pct_LMH = [];
    for i=2:4
        Pct_LMH = [Pct_LMH, bsxfun(@rdivide,sum(bsxfun(@times,Cat_mat_gender(:,i),Sims_Out.P_sim),1),sum(bsxfun(@times,Cat_mat_gender(:,1),Sims_Out.P_sim),1))'];
    end    
    
    Means_gender = [];
    for i=1:size(Cat_mat_gender,2)
        Means_gender = [Means_gender, sum(bsxfun(@rdivide,bsxfun(@times,Cat_mat_gender(:,i),Sims_Out.y1_gender_m4),sum(Cat_mat_gender(:,i),1)))'];
    end
    
    for i=1:Sim_reps
        Mean_Outcome_gender_pref(3,1) = Mean_Outcome_gender_pref(3,1) + Means_gender(i,1)/Sim_reps;
        Mean_Outcome_gender_pref(3,2) = Mean_Outcome_gender_pref(3,2) + Means_gender(i,2)/Sim_reps;
        Mean_Outcome_gender_pref(3,3) = Mean_Outcome_gender_pref(3,3) + Means_gender(i,3)/Sim_reps;
        Mean_Outcome_gender_pref(3,4) = Mean_Outcome_gender_pref(3,4) + Means_gender(i,4)/Sim_reps;
        Mean_Outcome_gender_pref(3,5) = Mean_Outcome_gender_pref(3,5) + Pct_LMH(i,1)/Sim_reps;
        Mean_Outcome_gender_pref(3,6) = Mean_Outcome_gender_pref(3,6) + Pct_LMH(i,2)/Sim_reps;
        Mean_Outcome_gender_pref(3,7) = Mean_Outcome_gender_pref(3,7) + Pct_LMH(i,3)/Sim_reps;
    end
 
    
    % H_gender
    if Net_OUT==0
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_H_gender_pref_OR.mat']);
    else
        load(['Sims_T2C_',num2str(sim_tol),'_',num2str(Sim_reps),'_H_gender_pref_OUT.mat']);
    end
    
    Pct_LMH = [];
    for i=2:4
        Pct_LMH = [Pct_LMH, bsxfun(@rdivide,sum(bsxfun(@times,Cat_mat_gender(:,i),Sims_Out.P_sim),1),sum(bsxfun(@times,Cat_mat_gender(:,1),Sims_Out.P_sim),1))'];
    end    
    
    Means_gender = [];
    for i=1:size(Cat_mat_gender,2)
        Means_gender = [Means_gender, sum(bsxfun(@rdivide,bsxfun(@times,Cat_mat_gender(:,i),Sims_Out.y1_gender_m4),sum(Cat_mat_gender(:,i),1)))'];
    end
    
    for i=1:Sim_reps
        Mean_Outcome_gender_pref(4,1) = Mean_Outcome_gender_pref(4,1) + Means_gender(i,1)/Sim_reps;
        Mean_Outcome_gender_pref(4,2) = Mean_Outcome_gender_pref(4,2) + Means_gender(i,2)/Sim_reps;
        Mean_Outcome_gender_pref(4,3) = Mean_Outcome_gender_pref(4,3) + Means_gender(i,3)/Sim_reps;
        Mean_Outcome_gender_pref(4,4) = Mean_Outcome_gender_pref(4,4) + Means_gender(i,4)/Sim_reps;
        Mean_Outcome_gender_pref(4,5) = Mean_Outcome_gender_pref(4,5) + Pct_LMH(i,1)/Sim_reps;
        Mean_Outcome_gender_pref(4,6) = Mean_Outcome_gender_pref(4,6) + Pct_LMH(i,2)/Sim_reps;
        Mean_Outcome_gender_pref(4,7) = Mean_Outcome_gender_pref(4,7) + Pct_LMH(i,3)/Sim_reps;
    end    
        

    
    Mean_Outcome_gender_pref
    
   
    if Net_OUT==0
        matrix2latex([Mean_Outcome_educ_pref; Mean_Outcome_gender_pref],['TableA4.tex'], 'format','%-9.3f')
    else
        matrix2latex([Mean_Outcome_educ_pref; Mean_Outcome_gender_pref],['TableA19.tex'], 'format','%-9.3f')
    end


            


